
############## Table A.7: Non-linearity

# non-linearity

dfbartik_linpol=dfbartik[dfbartik$testmonth=="May",]
dfbartik_linpol$highpm=ifelse(dfbartik_linpol$avgpm25_9>median(dfbartik_linpol$avgpm25_9),1,0)

#median 

bartik_dist_nonlin=as.formula(paste("cs_mn_all~ cs_mn_all_lag_cohort + ",districtcovariates,"  |factor(year) +factor(subject) + factor(grade)+factor(leaid) |(avgpm25_9 | I(avgpm25_9*highpm) ~ ",instname," + I(",instname,"*highpm))|leaid",sep="" ))

regmedian=felm(bartik_dist_nonlin,dfbartik_linpol,weights=dfbartik_linpol[[weightval]],na.action=na.omit)


bartik_dist_nonlin=as.formula(paste("cs_mn_all~ cs_mn_all_lag_cohort   + ", districtcovariates, " + ", acs ," |factor(year)  +factor(subject)   + factor(grade)+factor(leaid) |(avgpm25_9 | I(avgpm25_9*highpm) ~ ",instname," + I(",instname,"*highpm))|leaid",sep="" ))

regmedian_acs=felm(bartik_dist_nonlin,dfbartik_linpol,weights=dfbartik_linpol[[weightval]],na.action=na.omit)


bartik_dist_nonlin=as.formula(paste("cs_mn_all~ cs_mn_all_lag_cohort   + ", districtcovariates, " + ", acs ,"+", tempvarsavg,"|factor(year)  +factor(subject) + factor(grade)+factor(leaid) |(avgpm25_9 | I(avgpm25_9*highpm) ~ ",instname," + I(",instname,"*highpm))|leaid",sep="" ))

regmedian_acs_temp=felm(bartik_dist_nonlin,dfbartik_linpol,weights=dfbartik_linpol[[weightval]],na.action=na.omit)


stargazer(regmedian,regmedian_acs,regmedian_acs_temp,  keep="avgpm25_9",digits=4,out="output/TableA7.tex")